package com.zdyt.opc.controller;



import com.zdyt.opc.common.ResultEntity;
import com.zdyt.opc.entity.OpcData;
import com.zdyt.opc.entity.ItemData;
import com.zdyt.opc.entity.OtherData;
import com.zdyt.opc.service.OpcShowDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/opc/show")
public class OpcShowDataController {


    @Autowired
    OpcShowDataService opcShowDataService;

    @PostMapping("/getData")
    public ResultEntity<List<OpcData>> getDataByItemCode(@RequestBody ItemData itemData) {
        List<OpcData> dataByItemCode = opcShowDataService.getDataByItemCode(itemData.getItemCodes());
        return ResultEntity.successWithData(dataByItemCode);
    }

    @PostMapping("/receiveData")
    public ResultEntity<Void> receiveAndUpdateData(@RequestBody OpcData opcData){
        opcShowDataService.receiveAndUpdateData(opcData);
        return ResultEntity.successWithoutData();
    }

    @PostMapping("/updataOtherData")
    public ResultEntity<Void> updataOtherData( OtherData otherData){
        opcShowDataService.updataOtherData(otherData);
        return ResultEntity.successWithoutData();
    }

    @GetMapping("/getOtherDatas")
    public ResultEntity<List<OtherData>> getOtherDatas() {
        List<OtherData> otherDatas = opcShowDataService.getOtherDatas();
        return ResultEntity.successWithData(otherDatas);
    }
    @GetMapping("/getOtherDataByKey")
    public ResultEntity<OtherData> getOtherDataByKey(@RequestParam String name) {
        OtherData otherDataByKey = opcShowDataService.getOtherDataByKey(name);
        return ResultEntity.successWithData(otherDataByKey);
    }
}
